package utils;

import java.util.List;

import objects.Board;
import objects.Card;
import objects.CardType;
import objects.Character;
import objects.Room;
import objects.Weapon;

public class FactoryUI {

	/**
	 * Generate contradicting cards list in HTML format.
	 */
	public static String getChooseContradictHtml(List<Card> contradictCards, String contradictPlayer)
	{
		String cardsTag = "";

		String src;
		
		for (Card card : contradictCards) 
		{
			
			if (card.getType().equals(CardType.CHARACTER))
			{
				src = CaseMachine.getImgFromCharacter(Character.valueOf(card.getName()));
			}
			else if (card.getType().equals(CardType.ROOM))
			{
				src = CaseMachine.getImgFromRoom(Room.valueOf(card.getName()));
			}
			else
			{
				src = CaseMachine.getImgFromWeapon(Weapon.valueOf(card.getName()));
			}
			
			cardsTag += " <td> \r\n							" +
					"	<table>\r\n" + 
					"									<tr>\r\n" + 
					"										<td align=\"center\">\r\n" + 
					card.getName() +  
					"										</td>\r\n" + 
					"									</tr>\r\n" + 
					"									<tr>\r\n" + 
					"										<td>\r\n" + 
					"<img src=images/" + src + " name=\"" + card.getName() + "\" width=\"140px\" id=\"" + contradictPlayer + "\" height=\"140px\" class=\"card\"/>\r\n" + 
					"										</td>\r\n" + 
					"									</tr>\r\n" + 
					"								</table>\r\n" + 
					" </td>"; 
		}
		
		return "<td align=\"center\" width=\"100%\" colspan=\"3\">\r\n" + 
				"					<table>\r\n" + 
				"						<tr>\r\n" + 
				"							<td colspan=\""+ contradictCards.size() + "\" align=\"center\" width=\"100%\">\r\n" +  
				contradictPlayer + ", please choose one card to show:\r\n" + 
				"							</td>\r\n" + 
				"						</tr>\r\n" + 
				"						<tr>\r\n" + 
				 cardsTag + 
				"						</tr>\r\n" + 
				"						\r\n" + 
				"					</table>\r\n" + 
				"				</td>";
	}
	
	/**
	 * Generate a contradicting card in HTML format.
	 */
	public static String getShowedContradictHtml(Card card, String contradictPlayer)
	{
		String src = "";
		String currPlayer = Board.getInstance().getCurrPlayerInstance().getPlayerName();
		if (card.getType().equals(CardType.CHARACTER))
		{
			src = CaseMachine.getImgFromCharacter(Character.valueOf(card.getName()));
		}
		else if (card.getType().equals(CardType.ROOM))
		{
			src = CaseMachine.getImgFromRoom(Room.valueOf(card.getName()));
		}
		else
		{
			src = CaseMachine.getImgFromWeapon(Weapon.valueOf(card.getName()));
		}
		
		String cardsTag = " <td> \r\n							" +
		"	<table>\r\n" + 
		"									<tr>\r\n" + 
		"										<td>\r\n" + 
		card.getName() +  
		"										</td>\r\n" + 
		"									</tr>\r\n" + 
		"									<tr>\r\n" + 
		"										<td>\r\n" + 
		"<img src=images/" + src + " width=\"140px\" height=\"140px\" />\r\n" + 
		"										</td>\r\n" + 
		"									</tr>\r\n" + 
		"								</table>\r\n" + 
		" </td>"; 
		
		return "<td align=\"center\" width=\"100%\" colspan=\"3\">\r\n" + 
		"					<table>\r\n" + 
		"						<tr>\r\n" + 
		"							<td width=\"100%\" align=\"center\">\r\n" +  
		"							</td>\r\n" + 
		"						</tr>\r\n" + 
		"						<tr>\r\n" + 
		 cardsTag + 
		"						</tr>\r\n" + 
		"						\r\n" + 
		"					</table>\r\n" + 
		"				</td>";
		
	}
	
	/**
	 * Get room content in HTML format.
	 */
	public static String getRoomContentHtml(String stbRoomPlayers,String stbRoomWeapons,String stbRoomChars)
	{
		return "<td class=\"roomContent\" align=\"left\">" + 
				"		<div> " + 
				"			Players in current room:  <hr/>" + 
				"			<ul>" + stbRoomPlayers  + "</ul>" +
				"			 " +  
				"		</div> " + 
				"	</td> " + 
				"	<td  class=\"roomContent\" align=\"left\">" + 
				"		<div> " + 
				"			Weapons in current room:  <hr/>" + 
				"			<ul>" + stbRoomWeapons   + "</ul>" +
				"			 " + 
				"		</div> " + 
				"	</td> " + 
				"	<td  class=\"roomContent\" align=\"left\"> " + 
				"		<div> " + 
				"			Characters in current room:  <hr/>" + 
				"			<ul>" + stbRoomChars  + "</ul>" +
				"			 " + 
				"		</div> " + 
				"	</td>";
	}
	
	/**
	 *  Format a list in java into a list in HTML for UI display.
	 */
	public static String getListHtml(List<String> strings)
	{
		StringBuilder stringBuilder = new StringBuilder();
		
		stringBuilder.append("<ul>");
		for (String string : strings) {
			stringBuilder.append("<li>");
			stringBuilder.append(string);
			stringBuilder.append("</li>");
		}
		
		return stringBuilder.toString();
	}
}
